package app.beit.finportal.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import app.beit.finportal.bean.RelativeWebProgramsBean;
import app.beit.finportal.dao.RelativeWebProgramsDao;
import app.beit.finportal.entity.RelativeWebPrograms;
import app.beit.finportal.service.convert.RelativeWebProgramsConvert;

public class RelativeWebProgramsService {

	@Autowired
	private RelativeWebProgramsDao relativeWebProgramsDao;	

	public List<RelativeWebProgramsBean> getAll() throws Exception{
		final List<RelativeWebPrograms> results = this.relativeWebProgramsDao.getAll();
		if(results != null && results.size() > 0){
			return RelativeWebProgramsConvert.entityToBean(results);
		}
		return null;
	}

	public List<RelativeWebProgramsBean> getAllByTypesBackdoor(final String type) throws Exception{
		final List<RelativeWebPrograms> results = this.relativeWebProgramsDao.getAllByTypesBackdoor(type);
		if(results != null && results.size() > 0){
			return RelativeWebProgramsConvert.entityToBean(results);
		}
		return null;
	}

	public List<RelativeWebProgramsBean> getAllByTypes(final String type) throws Exception{
		final List<RelativeWebPrograms> results = this.relativeWebProgramsDao.getAllByTypes(type);
		if(results != null && results.size() > 0){
			return RelativeWebProgramsConvert.entityToBean(results);
		}
		return null;
	}

	public List<RelativeWebProgramsBean> getAllByTypesLastestDate(final String type) throws Exception{
		final List<RelativeWebPrograms> results = this.relativeWebProgramsDao.getAllByTypesLastestDate(type);
		if(results != null && results.size() > 0){
			return RelativeWebProgramsConvert.entityToBean(results);
		}
		return null;
	}

	public void add(final RelativeWebProgramsBean bean) throws Exception{
		this.relativeWebProgramsDao.add(RelativeWebProgramsConvert.beanToEntity(bean));
	}
	
	public void update(final RelativeWebProgramsBean bean) throws Exception{
		this.relativeWebProgramsDao.update(RelativeWebProgramsConvert.beanToEntity(bean));
	}
	
	public void delete(final RelativeWebProgramsBean bean) throws Exception{
		this.relativeWebProgramsDao.delete(RelativeWebProgramsConvert.beanToEntity(bean));
	}
}
